package com.gis3c.sys.web.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by hukekuan on 2017/9/5.
 */
public class MyInterceptor implements HandlerInterceptor {
    @Override
    public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response, Object object, Exception exception)
            throws Exception {
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response,
                           Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle ===> " + request);
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                             Object handler) throws Exception {
        System.out.println("========================preHandle start=========================");
        System.out.println("RequestURI ===> " + request.getRequestURI());
        System.out.println("QueryString ===> " + request.getQueryString());
        System.out.println("RequestURL ===> " + request.getRequestURL());
        System.out.println("ContextPath ===> " + request.getContextPath());
        System.out.println("LocalAddr ===> " + request.getLocalAddr());
        System.out.println("Referer ===> " + request.getHeader("Referer"));
        System.out.println("========================preHandle end=========================");
        if("/login".equals(request.getRequestURI().toString()) && request.getHeader("Referer") != null){
            System.out.println("++++++++++++++++++++++++++++");
            return false;
        }
        return true;
    }
}
